//
//  HYMyBookingFilterView.m
//  Booking
//
//  Created by Duntech on 2018/4/26.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMyBookingFilterView.h"

@interface HYMyBookingFilterView ()

@property (nonatomic,strong) UIView *detailBgView;
@property (nonatomic,strong) UIImageView *searchIconImgView;
@property (nonatomic,strong) UIButton *previousSelectBtn;

@property (nonatomic,strong) UIView *middleLine;
@property (nonatomic,strong) UILabel *middleLab;

@end

@implementation HYMyBookingFilterView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupSubViews];
        [self setupMasonryLayout];
        self.backgroundColor = KCOLOR(@"34bfce");
    }
    return self;
}

- (void)setupSubViews{
    
    [self addSubview:self.detailBgView];
    [self addSubview:self.searchIconImgView];
    [self addSubview:self.statusLabel];
    [self addSubview:self.officeLabel];
    [self addSubview:self.startTimeLabel];
    [self addSubview:self.endTimeLabel];
    [self addSubview:self.middleLine];
    [self addSubview:self.middleLab];
}

- (void)setupMasonryLayout{
    
    [_detailBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(60 * WIDTH_MULTIPLE);
    }];
    
    [_searchIconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(22 * WIDTH_MULTIPLE);
        make.left.equalTo(self).offset(10 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(15 * WIDTH_MULTIPLE);
        make.width.mas_equalTo(20 * WIDTH_MULTIPLE);
    }];
    
    [_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.detailBgView).offset(5 * WIDTH_MULTIPLE);
        make.left.equalTo(self.searchIconImgView.mas_right).offset(10 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(20 * WIDTH_MULTIPLE);
        make.width.mas_equalTo(KSCREEN_WIDTH / 2 - 60 * WIDTH_MULTIPLE);
    }];
    
    [_officeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.statusLabel);
        make.left.equalTo(self.startTimeLabel.mas_right).offset(10 * WIDTH_MULTIPLE);
        make.right.equalTo(self).offset(-20 * WIDTH_MULTIPLE);
    }];
    
    [_startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.right.equalTo(self.statusLabel);
        make.top.equalTo(self.statusLabel.mas_bottom).offset(5 * WIDTH_MULTIPLE);
        make.height.mas_equalTo(20 * WIDTH_MULTIPLE);
    }];
    
    [_endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.officeLabel);
        make.top.bottom.equalTo(self.startTimeLabel);
    }];
    
    [_middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.statusLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(2, 15));
    }];
    
    [_middleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.startTimeLabel.mas_centerY);
    }];
}

#pragma mark - action
- (void)buttonAction:(UIButton *)sender{
    
    self.previousSelectBtn.backgroundColor = [UIColor clearColor];
    self.previousSelectBtn.layer.borderColor = KAPP_WHITE_COLOR.CGColor;
    self.previousSelectBtn.layer.borderWidth = WIDTH_MULTIPLE;
    
    self.previousSelectBtn.selected = NO;
    sender.selected = YES;
    sender.backgroundColor = KAPP_THEME_COLOR;
    sender.layer.borderWidth = 0;
    self.previousSelectBtn = sender;
    
    if (self.ButtonChangeBlock) {
        self.ButtonChangeBlock(sender.tag - 100);
    }
    
}

#pragma mark - lazyload
- (UIView *)detailBgView{
    
    if (!_detailBgView) {
        _detailBgView = [UIView new];
        _detailBgView.backgroundColor = KAPP_FILTER_TOP_COLOR;
    }
    return _detailBgView;
}

- (UIImageView *)searchIconImgView{
    
    if (!_searchIconImgView) {
        
        _searchIconImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
        _searchIconImgView.contentMode = UIViewContentModeScaleAspectFit;
        _searchIconImgView.image = [UIImage imageNamed:@"search"];
        _searchIconImgView.clipsToBounds = YES;
    }
    return _searchIconImgView;
}

- (UILabel *)statusLabel{
    
    if (!_statusLabel) {
        _statusLabel = [UILabel new];
        _statusLabel.textColor = KAPP_WHITE_COLOR;
        _statusLabel.font = KFitFont(14);
        _statusLabel.textAlignment = NSTextAlignmentCenter;
        _statusLabel.text = NSLocalizedString(@"allBookings", nil);
    }
    return _statusLabel;
}

- (UILabel *)officeLabel{
    
    if (!_officeLabel) {
        _officeLabel = [UILabel new];
        _officeLabel.textColor = KAPP_WHITE_COLOR;
        _officeLabel.font = KFitFont(14);
        _officeLabel.textAlignment = NSTextAlignmentCenter;
        _officeLabel.text = NSLocalizedString(@"allOffices", nil);
    }
    return _officeLabel;
}

- (UILabel *)startTimeLabel{
    
    if (!_startTimeLabel) {
        _startTimeLabel = [UILabel new];
        _startTimeLabel.textColor = KAPP_WHITE_COLOR;
        _startTimeLabel.font = KFitFont(14);
        _startTimeLabel.textAlignment = NSTextAlignmentCenter;
        _startTimeLabel.text = [HYDateHandle getCurrentDateStrYYYYMMDDWithTimeInterval:0];
    }
    return _startTimeLabel;
}

- (UILabel *)endTimeLabel{
    
    if (!_endTimeLabel) {
        _endTimeLabel = [UILabel new];
        _endTimeLabel.textColor = KAPP_WHITE_COLOR;
        _endTimeLabel.font = KFitFont(14);
        _endTimeLabel.textAlignment = NSTextAlignmentCenter;
        _endTimeLabel.text = [HYDateHandle getCurrentDateStrYYYYMMDDWithTimeInterval:7 * 24 * 60 * 60];
    }
    return _endTimeLabel;
}

-(UILabel *)middleLab{
    if (!_middleLab){
        _middleLab = [[UILabel alloc]init];
        _middleLab.textColor = KAPP_WHITE_COLOR;
        _middleLab.font = KFitFont(14);
        _middleLab.text = NSLocalizedString(@"to", nil);
    }
    return _middleLab;
}

-(UIView *)middleLine{
    if (!_middleLine) {
        _middleLine = [[UIView alloc]init];
        _middleLine.backgroundColor = KAPP_WHITE_COLOR;
        _middleLine.layerCornerRadius = 1.0;
    }
    return _middleLine;
}

@end
